#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :csv_readf_ui.py
# @Time      :2023/12/14 23:47
# @Author    :retro_star
"""这个文件实现读csv文件的窗口ui
"""

from PyQt5.QtWidgets import QFileDialog

from ui_file.main_window import *


class CSVRead(QWidget):
    def __init__(self):
        super().__init__()
        self.open_file_btn = QPushButton('将csv文件拖入此窗口或点击选择文件')
        self.file_dialog = QFileDialog()
        self.ui_set()

    def ui_set(self):
        # 窗口设置
        self.open_file_btn.setParent(self)
        self.setAcceptDrops(True)
        # 按钮设置
        self.open_file_btn.clicked.connect(self.open_file_dialog)

    def open_file_dialog(self):
        print(self.file_dialog.getOpenFileName())

    def dragEnterEvent(self, a0):
        """当有文件被拖入窗口时进行判断，决定是否接受此拖拽事件"""
        if a0.mimeData().urls():
            a0.acceptProposedAction()
        else:
            a0.ignore()

    def dropEvent(self, a0):
        """当拖拽事件结束时调用"""
        print(a0.mimeData().urls())
